package info.brenstar.boxedin.sprites;

import info.brenstar.boxedin.core.Sprite;
import info.brenstar.boxedin.core.Updated;

import java.io.InputStream;

import org.newdawn.slick.*;
import org.newdawn.slick.geom.Point;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.util.ResourceLoader;

public class Platform extends Sprite implements Updated {
	
	private int hue = 0, t=0;
	private Color tint;
	private Point location_last;
	private int row, col;
	
	public Platform() {
		resource = "res/tileset.png";
		location_last = new Point(0,0);
	}
	
	public Platform(float x, float y) {
		super(x, y);
		mask = new Rectangle(x, y, 32f, 32f);
		resource = "res/tileset.png";
	}
	
	public Platform(float x, float y, int initHue) {
		super(x, y);
		mask = new Rectangle(x, y, 32f, 32f);
		hue = initHue;
		resource = "res/tileset.png";
		collide = true;
	}
	
	@Override
	public void update() {
		if (t==0) {
			hue+=3;
			if (hue > 360) { hue = 0; }
			int rgb = java.awt.Color.HSBtoRGB(hue / 360f, 1f, 1f);
			tint = new Color(rgb);
			t = 3;
		} else { t--; }
	}

	@Override
	public void render(Graphics g) {
		if (sheet!=null) {
			g.drawImage(sheet.getSprite(col, row), x, y, tint);
		} 
	}

	@Override
	public void init() {
		if (ResourceLoader.resourceExists(resource)) {
			InputStream stream = ResourceLoader.getResourceAsStream(resource);
			try {
				image = new Image(stream, resource, false);
				sheet = new SpriteSheet(image, 32, 32);
			} catch (SlickException e) { }
		} else {
			System.out.println("Error [140]: Resoure loading for object Platform has failed");
			
		}

	}

	@Override
	public void unload() {
		// TODO Auto-generated method stub

	}

	@Override
	public void kill() {
		// TODO Auto-generated method stub

	}
	
	public void setTile(int row, int col) {
		this.row = row;
		this.col = col;
	}
	
}
